﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IA2NeuralNetwork.CharMap
{
    public class CharLabel
    {
        public byte[] Data;
        
        public CharLabel(byte[] data)
        {
            this.Data = data;
        }

        public bool Equals(CharLabel obj)
        {
            for (int i = 0; i < this.Data.Length; i++)
            {
                try
                {
                    if (this.Data[i] != obj.Data[i])
                    {
                        return false;
                    }
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return true;
        }

        #region Cast

        private int GetMapPosition()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            List<CharLabel> list = map.LabelMap;
            for (int i = 0; i < list.Count(); i++)
            {
                if (this.Equals(list[i]))
                {
                    return i;
                }
            }

            return -1;
        }

        public CharByte ToCharByte()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            int i = this.GetMapPosition();
            return map.BytesMap[i];
        }

        public static implicit operator CharByte(CharLabel obj)
        {
            return obj.ToCharByte();
        }

        public CharRaw ToCharRaw()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            int i = this.GetMapPosition();
            return map.RawMap[i];
        }

        public static implicit operator CharRaw(CharLabel obj)
        {
            return obj.ToCharRaw();
        }

        #endregion
    }
}
